﻿using System;
using System.Collections.Generic;
using System.Web;
using MoiGioiHDBank.DTO;
using System.Data.Common;
using System.Data;
using System.Data.SqlClient;

namespace MoiGioiHDBank.DAO
{
    public class LienKetNganHangDAO
    {
        public static LienKetNganHang LayThongTinNganHangLienKet(string tenNganHang)
        {
            SQLDataAccessHelper dl = new SQLDataAccessHelper();
            string sqlString = @"SELECT *
                                 FROM LIENKETNGANHANG
                                 WHERE (TENNGANHANG = @TenNganHang)";
            List<DbParameter> listparams = new List<DbParameter>();

            DbParameter para = dl.DoiSo();
            para.ParameterName = "TenNganHang";
            para.DbType = DbType.String;
            para.Direction = ParameterDirection.Input;
            para.Value = tenNganHang;
            listparams.Add(para);

            SqlCommand sql = new SqlCommand(sqlString);
            DataTable dt = dl.ThucThiTruyVan(sql, listparams);
            if (dt.Rows.Count == 0)
            {
                return null;
            }
            else
            {
                LienKetNganHang lknh = new LienKetNganHang();
                lknh.TenNganHang = dt.Rows[0]["TENNGANHANG"].ToString();
                lknh.URL = dt.Rows[0]["URL"].ToString();
                lknh.TenWebservice = dt.Rows[0]["TENWEBSERVICE"].ToString();
                lknh.UserName = dt.Rows[0]["USERNAME"].ToString();
                lknh.Password = dt.Rows[0]["PASSWORD"].ToString();
                lknh.SoThe = MineUtils.GiaiMa(MineUtils.StringToByteArray( dt.Rows[0]["SOTHE"].ToString()));
                return lknh;
            }
        }
    }
}